using GamFi.Admin.API.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace GamFi.Admin.API.Persistence.Configurations;

public class UserInfoConfiguration : IEntityTypeConfiguration<UserInfo>
{
    /// <inheritdoc />
    public void Configure(EntityTypeBuilder<UserInfo> builder)
    {
        builder.HasKey(x => x.Id);

        builder.Property(p => p.FirstName);

        builder.Property(p => p.LastName);

        builder.Property(p => p.Patronymic);

        builder.Property(p => p.CountryId);

        builder.Property(p => p.UserId);

        builder.Property(p => p.ImageId);

        builder.HasOne(x => x.Country)
            .WithMany(y => y.Users)
            .HasForeignKey(x => x.CountryId)
            .OnDelete(DeleteBehavior.SetNull);

        builder.HasOne(x => x.User)
            .WithOne(y => y.UserInfo)
            .HasForeignKey<UserInfo>(x => x.UserId)
            .OnDelete(DeleteBehavior.Cascade);
    }
}